package com.eastfair.projectcore.controller;

import com.eastfair.projectcore.dto.HotImagePageQuery;
import com.eastfair.projectcore.dto.HotImageSaveDTO;
import com.eastfair.projectcore.dto.HotImageUpdateDTO;
import com.eastfair.projectcore.entity.HotImage;
import com.eastfair.projectcore.service.HotImageService;
import com.eastfair.projectcore.vo.HotImageVO;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 前端控制器
 * 电子橱窗表
 * </p>
 *
 * @author ligang
 * @date 2021-08-09
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/hotImage")
@Api(value = "HotImage", tags = "电子橱窗表")
public class HotImageController extends SuperController<HotImageService, Long, HotImage, HotImagePageQuery, HotImageSaveDTO, HotImageUpdateDTO> {

    @Autowired
    private EchoService echoService;

    @Override
    public void handlerResult(IPage<HotImage> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list) {
        List<HotImage> hotImageList = list.stream().map((map) -> {
            HotImage hotImage = HotImage.builder().build();
            //TODO 请在这里完成转换
            return hotImage;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(hotImageList));
    }

    /**
     * 查询电子橱窗信息
     *
     * @param exhibitionId 展会id
     * @return
     */
    @ApiOperation(value = "查询电子橱窗信息", notes = "查询电子橱窗信息")
    @GetMapping("/findAllById")
    public List<HotImageVO> findAllById(@RequestParam(value = "exhibitionId") Long exhibitionId) {
        return baseService.findIdAll(exhibitionId);
    }

    /**
     * 推荐橱窗
     *
     * @param id          橱窗id
     * @param isRecommend 是否推荐 true是 false否
     * @return
     */
    @ApiOperation(value = "推荐橱窗", notes = "推荐橱窗")
    @GetMapping("/recommendHotImage")
    public R recommendHotImage(@RequestParam(value = "id") Long id, @RequestParam(value = "isRecommend") Boolean isRecommend) {
        return baseService.recommendHotImage(id, isRecommend);
    }

    /**
     * 置顶橱窗
     *
     * @param id 橱窗id
     * @return
     */
    @ApiOperation(value = "置顶橱窗", notes = "置顶橱窗")
    @GetMapping("/top")
    public R top(@RequestParam(value = "id") Long id) {
        return baseService.top(id);
    }

}
